#include<iostream>
#include<thread>
#include<condition_variable>
#include<mutex>
using namespace std;



int main()
{
	mutex m;
	bool falg = true;
	condition_variable cd;
	int cnt = 100;
	thread t1([&]() {
		int i = 1;
		while (i <= cnt)
		{
			unique_lock<mutex> mut(m);
			while (!falg)
			{
				cd.wait(mut);
			}

			cout << "thread 1: " << i << endl;
			i += 2;
			falg = false;
			cd.notify_one();
		}
		});

	thread t2([&]() {
		int i = 2;
		while (i <= cnt)
		{
			unique_lock<mutex> mut(m);

			while (falg)
			{
				cd.wait(mut);
			}

			cout << "thread 2: " << i << endl;
			i += 2;
			falg = true;
			cd.notify_one();
		}
		});

	t1.join();
	t2.join();
	return 0;
}